package com.shishuo.cms.service;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.dao.GoodsItemKeywordsDao;
import com.shishuo.cms.entity.GoodsItemKeywordsEntity;
import com.shishuo.cms.entity.vo.PageVo;
@Service
public class GoodsItemKeywordsService extends BaseService<GoodsItemKeywordsEntity, Long>
{
	private GoodsItemKeywordsDao goodsItemKeywordsDao;
	@Autowired
	public void setGoodsItemKeywordsDao(GoodsItemKeywordsDao goodsItemKeywordsDao)
	{
		super.setBaseDao(goodsItemKeywordsDao);
		this.goodsItemKeywordsDao = goodsItemKeywordsDao;
	}
	public PageVo<GoodsItemKeywordsEntity> getAllListPage(int pageNum,int pageSize) throws Exception
	{
		PageVo<GoodsItemKeywordsEntity> pageVo = new PageVo<GoodsItemKeywordsEntity>(pageNum);
		pageVo.setDirPath("/goods/hotKeywords/");
		pageVo.setRows(pageSize);
		List<GoodsItemKeywordsEntity> list = this
				.getAllList(pageVo.getOffset(), pageVo.getRows());
		pageVo.setList(list);
		pageVo.setCount(this.getAllListCount());
		return pageVo;
	}
	public boolean saveKeywords(String goodsKeywords) throws Exception {
		if(! goodsItemKeywordsDao.existGoodsItemKeywordsEntity(goodsKeywords)){
			GoodsItemKeywordsEntity goodsItemKeywordsEntity=new GoodsItemKeywordsEntity();
			goodsItemKeywordsEntity.setCreateDate(new Date());
			goodsItemKeywordsEntity.setGoodsKeywords(goodsKeywords);
			goodsItemKeywordsEntity.setGoodsKeywordsAlias(goodsKeywords);
			this.insert(goodsItemKeywordsEntity);
			return true;
		}else {
			goodsItemKeywordsDao.updateSearchTimesByKeywords(goodsKeywords);
		}
		return false;
	}
}
